var removeElement = function(nums, val) {
    const n = nums.length
    let j=0
    for(let i=0;i<n;i++){
        if(nums[i]==val) continue
        nums[j++]=nums[i]
    }
    return j
};

console.log(removeElement([1,2,3,4,4,4,5,6,7],4));